<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../static/js/crypto-js.js"></script>
</head>
<body>

</body>
<script>

    var key = CryptoJS.enc.Utf8.parse("shudianquanjings");
    var iv = CryptoJS.enc.Utf8.parse('henanguowangsbdz');


    //加密方法
    function decrypt(word) {
        if(!word) return;
        var encryptedHexStr = CryptoJS.enc.Hex.parse(word);
        var srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
        var decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
        var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
        return decryptedStr.toString();
    }

    //加密方法
    function encrypt(word) {
        if(!word) return;
        var srcs = CryptoJS.enc.Utf8.parse(word);
        var encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
        return encrypted.ciphertext.toString().toUpperCase();
    }

    var ciphertext = encrypt('weizhixi');
    console.info(ciphertext);
    console.info(decrypt(ciphertext))
</script>
</html>